function beer(money,price,bottle,lid){
    let purchase=Math.floor(money/price)
    let count=bottles=lids=purchase
    let exchange_bottles,exchange_lids
    while(bottles>=bottle||lids>=lid){
        exchange_bottles=Math.floor(bottles/bottle)
        bottles=exchange_bottles+bottles%bottle
        exchange_lids=Math.floor(lids/lid)
        lids=exchange_lids+lids%lid
        count+=exchange_bottles+exchange_lids
    }
    return count
}

console.log(beer(270,3,2,5))
